# -*- Python -*- vim: set ft=python ts=4 sw=4 expandtab tw=79:
# Configuration file for the 'lit' test runner.

import os
import re
import subprocess
import lit.formats

# Tell pylint that we know config and lit_config exist somewhere.
if 'PYLINT_IMPORT' in os.environ:
    config = object()
    lit_config = object()

def append_dynamic_library_path(path):
    if config.operating_system == 'Windows':
        name = 'PATH'
        sep = ';'
    elif config.operating_system == 'Darwin':
        name = 'DYLD_LIBRARY_PATH'
        sep = ':'
    else:
        name = 'LD_LIBRARY_PATH'
        sep = ':'
    if name in config.environment:
        config.environment[name] = path + sep + config.environment[name]
    else:
        config.environment[name] = path
#    config.environment['PYTHONPATH'] = config.ompd_module + sep + config.environment['PYTHON_PATH']

# name: The name of this test suite.
config.name = 'ompd-test'

# suffixes: A list of file extensions to treat as test files.
config.suffixes = ['.c']

# test_source_root: The root path where tests are located.
#config.test_source_root = os.path.dirname(__file__)
config.test_source_root = config.ompd_test_src

# test_exec_root: The root object directory where output is placed
config.test_exec_root = config.ompd_obj_root

# test format
config.test_format = lit.formats.ShTest()

# compiler flags
config.test_flags = " -I " + config.test_source_root + " -I " + config.ompt_include_dir + \
    " " + config.test_extra_flags + " -L " + config.library_dir

append_dynamic_library_path(config.library_dir)
append_dynamic_library_path(config.ompd_library_dir)

# Disable OMPT tests if FileCheck was not found
if config.test_filecheck == "":
    lit_config.note("Not testing OMPT_OMPD because FileCheck was not found")

if 'Linux' in config.operating_system:
    config.available_features.add("linux")

# to run with icc INTEL_LICENSE_FILE must be set
if 'INTEL_LICENSE_FILE' in os.environ:
    config.environment['INTEL_LICENSE_FILE'] = os.environ['INTEL_LICENSE_FILE']
if 'OMP_NUM_THREADS' in os.environ:
    config.environment['OMP_NUM_THREADS'] = os.environ['OMP_NUM_THREADS']
#config.environment['ompd'] = "/home/gu620893/LLVM-openmp-master/install/"

config.substitutions.append(("%gdb-compile-and-run", "%gdb-compile && %gdb-run"))

config.substitutions.append(("%gdb-compile",
    "%test_c_compiler -fopenmp -g -gdwarf-4 %s -o %t " + config.test_flags))
config.substitutions.append(("%test_c_compiler", config.test_c_compiler))
config.substitutions.append(("%gdb-run",
    "env OMP_DEBUG=enabled gdb -x " + config.ompd_obj_root + "/../gdb-plugin/python-module/ompd/__init__.py -x " \
    + config.ompd_test_src + "/test.cmd %t "))

config.substitutions.append(("%gdb-test",
    "env OMP_DEBUG=enabled gdb -x " + config.ompd_obj_root + "/../gdb-plugin/python-module/ompd/__init__.py "))
    
config.substitutions.append(("%ompt-tool", 
    config.ompt_plugin))

config.substitutions.append(("FileCheck", config.test_filecheck))

